package com.zhiyou100.controller;

import com.zhiyou100.entity.ResponseJson;
import com.zhiyou100.exception.DirectoryException;
import com.zhiyou100.exception.FileException;
import com.zhiyou100.exception.LoginException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常拦截器
 *
 * @author yang
 * @version 1.0.0
 * @date 2020-10-10 20:05
 */
@RestControllerAdvice
public class ExceptionController {

    @ExceptionHandler(FileException.class)
    public ResponseJson<Object> fileException(FileException throwable) {
        return ResponseJson.builder()
                .status(500)
                .message("文件异常 " + throwable.getMessage())
                .data(throwable)
                .build();
    }

    @ExceptionHandler(DirectoryException.class)
    public ResponseJson<Object> directoryException(DirectoryException throwable) {
        return ResponseJson.builder()
                .status(500)
                .message("文件夹异常 " + throwable.getMessage())
                .data(throwable)
                .build();
    }

    @ExceptionHandler(LoginException.class)
    public ResponseJson<Object> loginException(LoginException e) {
        return ResponseJson.builder()
                .status(500)
                .message("登陆失败！！ " + e.getMessage())
                .data(e)
                .build();
    }
}
